package com.slfx.idgen.demo.idgen.config;

import com.slfx.idgen.demo.idgen.properties.IdgenProperties;
import com.slfx.idgen.demo.idgen.properties.SnowflakeProperties;
import com.slfx.idgen.demo.idgen.snowflake.IdWorker;
import com.slfx.idgen.demo.idgen.snowflake.SnowflakeServer;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@AutoConfigureAfter(IdWorkerConfiguration.class)
@Import({IdWorkerConfiguration.class})
@EnableConfigurationProperties({SnowflakeProperties.class, IdgenProperties.class})
public class SnowflakeAutoConfiguration {

    private SnowflakeProperties snowflakeProperties;

    public SnowflakeAutoConfiguration(SnowflakeProperties snowflakeProperties) {
        this.snowflakeProperties = snowflakeProperties;
    }

    @Bean("snowflakeServer")
    public SnowflakeServer init(IdWorker idWorker) {
        return new SnowflakeServer(snowflakeProperties, idWorker);
    }


}
